package com.songcha.sakura.ui.adapter

import android.content.Context
import android.view.View


import androidx.constraintlayout.widget.ConstraintLayout
import androidx.databinding.ViewDataBinding
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.songcha.library_common.util.ScreenUtil
import com.songcha.library_common.util.dp2px
import com.songcha.sakura.R
import com.songcha.sakura.bean.ComicListBean
import com.songcha.sakura.databinding.ItemComicBinding


class ComicAdapter<DB:ViewDataBinding>(val mContext: Context, resId:Int, list:MutableList<ComicListBean.ComicBean>)
    : BaseQuickAdapter<ComicListBean.ComicBean,BaseDataBindingHolder<DB>>(resId,list) {

    init {
        addChildClickViewIds(R.id.ccl_comic_parent)
    }

    companion object{

    }



    override fun convert(holder: BaseDataBindingHolder<DB>, item: ComicListBean.ComicBean) {
        val db=holder.dataBinding as ItemComicBinding

        //db.cclComicParent.tag=item.title
       /* val comicLp =  db.cclComicParent.layoutParams as ConstraintLayout.LayoutParams
        comicLp.width = ((ScreenUtil.getScreenWidth(mContext)-20.dp2px()) / 2)
        db.cclComicParent.layoutParams = comicLp*/

        holder.setText(R.id.tv_title, item.title)
        holder.setText(R.id.tv_describe, item.describe)
        holder.setText(R.id.tv_score, item.score)
        holder.setText(R.id.tv_update, item.update)

        if(item.update.isBlank()){
            db.sakuraComicFl.visibility=View.INVISIBLE
        }else{
            db.sakuraComicFl.visibility=View.VISIBLE
        }

        db.tvScore.textSize=12f
        db.tvUpdate.textSize=12f
        db.tvDescribe.textSize=14f
        db.tvTitle.apply {
            textSize=15f
        }

        //必须在adapter中设置图片高度
        db.ivComic.apply {
           (layoutParams as ConstraintLayout.LayoutParams).apply {
                height=255.dp2px()
            }

            Glide.with(context).load(item.data_original).into(this)
        }

    }

}